﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdministratorjiSeznam.aspx.cs"
    Inherits="Sio.Mdm.Web.Instalacija.AdministratorjiSeznam" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>SIO - MDM :: Instalacija : Seznam administratorjev</title>
    <ext:XScript ID="XScript1" runat="server">

        <script type="text/javascript">
        var spoliRenderer = function(value) {
            var r = StoreSpoli.getById(value);
            if (Ext.isEmpty(r)) { return ""; }
            return r.data.Naziv;
        };
        var dodajZapis = function () {
          var grid = #{GridUceciSeznam};
          grid.getRowEditor().stopEditing();    
          grid.insertRecord(0, {
              IdmStevilka: -99,
			        Naziv   : "",
          });
          
          grid.getView().refresh();
          grid.getSelectionModel().selectRow(0);
          grid.getRowEditor().startEditing(0);
        }  
        
        var handleCommand = function (command, url, title, args, tabId, Idm){
          if (command == "Uredi")
           {
             openTab(url, title, args, tabId);      
             //Ext.net.DirectMethods.OdpriPodrobnosti(url, title, args, tabId);
           }
           else if (command == "NastaviGeslo")
           {
             //Ext.Msg.alert(command, url);   
             //Ext.net.DirectMethods.NastaviGeslo(args);
             #{SpremeniGeslo}.addParameter('Idm', Idm);
             #{SpremeniGeslo}.show();
           }
        }
    </script>

    </ext:XScript>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:Store ID="StoreObcine" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="ObcinaId">
                <Fields>
                    <ext:RecordField Name="ObcinaId" Type="Int" />
                    <ext:RecordField Name="Naziv" Type="String" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="StorePoste" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="PostaId">
                <Fields>
                    <ext:RecordField Name="PostaId" Type="Int" />
                    <ext:RecordField Name="PostnaStevilka" Type="Int" />
                    <ext:RecordField Name="Naziv" Type="String" />
                    <ext:RecordField Name="StevilkaNaziv" Type="String">
                        <Convert Handler="return record.PostnaStevilka+' '+record.Naziv;" />
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="StoreSpoli" runat="server">
        <Reader>
            <ext:ArrayReader IDProperty="SpolID">
                <Fields>
                    <ext:RecordField Name="SpolID" Type="Int" />
                    <ext:RecordField Name="Naziv" Type="String" />
                </Fields>
            </ext:ArrayReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server" Layout="Fit">
        <Content>
            <ext:BorderLayout ID="BorderLayout1" runat="server">
                <North Collapsible="false" MinHeight="80" Split="true">
                    <sio:GridPanel ID="GridUceciSeznam" runat="server" StripeRows="true" TrackMouseOver="true"
                        Width="700" Height="200">
                        <Plugins>
                            <ext:RowEditor ID="RowEditor1" runat="server" SaveText="Shrani" CancelText="Prekliči"
                                ClicksToEdit="2">
                                <DirectEvents>
                                    <AfterEdit OnEvent="UrediPodatke">
                                        <ExtraParams>
                                            <ext:Parameter Mode="Raw" Name="data" Value="r.data" />
                                        </ExtraParams>
                                    </AfterEdit>
                                </DirectEvents>
                            </ext:RowEditor>
                            <ext:GridFilters runat="server">
                                <Filters>
                                    <ext:StringFilter DataIndex="Ime" />
                                    <ext:StringFilter DataIndex="Priimek" />
                                    <ext:ListFilter DataIndex="Spol" Options="moški, ženska" />
                                    <ext:NumericFilter DataIndex="IdmStevilka" />
                                </Filters>
                            </ext:GridFilters>
                        </Plugins>
                        <Store>
                            <ext:Store ID="StoreUceciSeznam" runat="server">
                                <SortInfo Field="Priimek" />
                                <Reader>
                                    <ext:JsonReader IDProperty="IdmStevilka">
                                        <Fields>
                                            <ext:RecordField Name="IdmStevilka" Type="Int" />
                                            <ext:RecordField Name="VlogaId" Type="Int" />
                                            <ext:RecordField Name="Ime" Type="String" />
                                            <ext:RecordField Name="Priimek" Type="String" />
                                            <ext:RecordField Name="Spol" Type="Int" />
                                            <ext:RecordField Name="UporabniskoIme" Type="String" />
                                            <ext:RecordField Name="EMail" Type="String" />
                                        </Fields>
                                    </ext:JsonReader>
                                </Reader>
                            </ext:Store>
                        </Store>
                        <ColumnModel ID="ColumnModel1" runat="server">
                            <Columns>
                                <ext:RowNumbererColumn />
                                <ext:Column ColumnID="IdmStevilka" Hidden="true" Hideable="false" DataIndex="IdmStevilka">
                                </ext:Column>
                                <ext:Column ColumnID="VlogaId" Hidden="true" Hideable="false" DataIndex="VlogaId">
                                </ext:Column>
                                <ext:Column ColumnID="Ime" Header="Ime" DataIndex="Ime">
                                    <Editor>
                                        <ext:TextField runat="server" AllowBlank="false" MinLength="2" MinLengthText="Vpišite ime"
                                            BlankText="Vpišite ime" />
                                    </Editor>
                                </ext:Column>
                                <ext:Column Header="Priimek" DataIndex="Priimek">
                                    <Editor>
                                        <ext:TextField runat="server" AllowBlank="false" MinLength="2" MinLengthText="Vpišite priimek"
                                            BlankText="Vpišite priimek" />
                                    </Editor>
                                </ext:Column>
                                <ext:Column Header="Spol" DataIndex="Spol">
                                    <Renderer Fn="spoliRenderer" />
                                    <Editor>
                                        <ext:ComboBox ID="cbSpoli" runat="server" TypeAhead="true" SelectOnFocus="true" Editable="true"
                                            Mode="Local" ForceSelection="true" StoreID="StoreSpoli" ValueField="SpolID" DisplayField="Naziv" />
                                    </Editor>
                                </ext:Column>
                                <ext:Column Header="Uporabniško ime" DataIndex="UporabniskoIme" Width="150">
                                    <Editor>
                                        <ext:TextField runat="server" AllowBlank="false" MinLength="3" MinLengthText="Vpišite uporabniško ime"
                                            BlankText="Vpišite uporabnisko ime" />
                                    </Editor>
                                </ext:Column>
                                <ext:Column Header="Email" DataIndex="EMail" Width="150">
                                    <Editor>
                                        <ext:TextField runat="server" AllowBlank="false" MinLength="5" MinLengthText="Vpišite email"
                                            BlankText="Vpišite email" />
                                    </Editor>
                                </ext:Column>
                                <ext:CommandColumn Width="150">
                                    <Commands>
                                        <ext:GridCommand Icon="NoteEdit" CommandName="Uredi" Text="Uredi">
                                            <ToolTip Text="Uredi" />
                                        </ext:GridCommand>
                                        <ext:GridCommand Icon="LockOpen" CommandName="NastaviGeslo" Text="Nastavi geslo">
                                            <ToolTip Text="NastaviGeslo" />
                                        </ext:GridCommand>
                                    </Commands>
                                </ext:CommandColumn>
                            </Columns>
                        </ColumnModel>
                        <Listeners>
                            <Command Handler="handleCommand(command,'../Uporabnik/Akter.aspx', 'Administrator '+record.data.Ime+' '+record.data.Priimek, {idm: record.id }, 'akter'+record.id, record.id);" />
                        </Listeners>
                        <SelectionModel>
                            <ext:CheckboxSelectionModel runat="server">
                                <Listeners>
                                    <RowSelect Handler="{#{StoreDodeljeno}.reload();}" Buffer="250" />
                                </Listeners>
                            </ext:CheckboxSelectionModel>
                        </SelectionModel>
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                                <Items>
                                    <sio:Button runat="server" ID="Add" Text="Dodaj" Icon="Add">
                                        <Listeners>
                                            <Click Fn="dodajZapis" />
                                        </Listeners>
                                        <%--showDialog(#{RazredAddUceci}, {letoid: Ext.urlDecode(window.location.search.substring(1)).letoid, razredid: Ext.urlDecode(window.location.search.substring(1)).razredid });" /></Listeners>--%>
                                    </sio:Button>
                                    <sio:Button runat="server" ID="Remove" Text="Odstrani" Icon="Delete">
                                        <DirectEvents>
                                            <Click OnEvent="OdstraniAdministratorje" After="#{StoreUceciSeznam}.reload();">
                                                <Confirmation ConfirmRequest="true" Message="Izbrišem izbrane administratorje?" />
                                                <ExtraParams>
                                                    <ext:Parameter Name="selected" Mode="Raw" Value="Ext.encode(#{GridUceciSeznam}.getRowsValues({selectedOnly:true}))" />
                                                </ExtraParams>
                                            </Click>
                                        </DirectEvents>
                                    </sio:Button>
                                    <ext:ToolbarSeparator />
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                    </sio:GridPanel>
                </North>
                <West Split="true">
                    <sio:GridPanel ID="GridDodeljeno" Title="Dodeljene organizacije" Width="300" EnableDragDrop="true"
                        runat="server" StripeRows="true" TrackMouseOver="true">
                        <Plugins>
                            <ext:GridFilters ID="GridFiltersDodeljeno" runat="server">
                                <Filters>
                                    <ext:NumericFilter DataIndex="OrganizacijaId" />
                                    <ext:StringFilter DataIndex="Naziv" />
                                </Filters>
                            </ext:GridFilters>
                        </Plugins>
                        <Store>
                            <ext:Store ID="StoreDodeljeno" runat="server" OnRefreshData="GridDodeljenoRefresh">
                                <Reader>
                                    <ext:JsonReader IDProperty="OrganizacijaId">
                                        <Fields>
                                            <ext:RecordField Name="OrganizacijaId" Type="Int" />
                                            <ext:RecordField Name="Naziv" Type="String" />
                                        </Fields>
                                    </ext:JsonReader>
                                </Reader>
                                <BaseParams>
                                    <ext:Parameter Name="IdmStevilka" Value="#{GridUceciSeznam}.getSelectionModel().hasSelection() ? #{GridUceciSeznam}.getSelectionModel().getSelected().id : -1"
                                        Mode="Raw" />
                                </BaseParams>
                            </ext:Store>
                        </Store>
                        <ColumnModel runat="server">
                            <Columns>
                                <ext:RowNumbererColumn />
                                <ext:Column ColumnID="OrganizacijaId" Hidden="true" Hideable="false" DataIndex="OrganizacijaId">
                                </ext:Column>
                                <ext:Column Header="Naziv organizacije" DataIndex="Naziv" Width="200">
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <SelectionModel>
                            <ext:CheckboxSelectionModel runat="server" />
                        </SelectionModel>
                        <TopBar>
                            <ext:Toolbar runat="server" Width="500">
                                <Items>
                                    <ext:ToolbarFill />
                                    <sio:Button runat="server" Text="Odstrani" Icon="ArrowRight">
                                        <DirectEvents>
                                            <Click OnEvent="OdstraniOrganizacije" After="#{StoreDodeljeno}.reload();">
                                                <Confirmation ConfirmRequest="true" Message="Odstranim izbrane organizacije?" />
                                                <ExtraParams>
                                                    <ext:Parameter Name="selected" Mode="Raw" Value="Ext.encode(#{GridDodeljeno}.getRowsValues({selectedOnly:true}))" />
                                                    <ext:Parameter Name="IdmStevilka" Value="#{GridUceciSeznam}.getSelectionModel().hasSelection() ? #{GridUceciSeznam}.getSelectionModel().getSelected().id : -1"
                                                        Mode="Raw" />
                                                </ExtraParams>
                                            </Click>
                                        </DirectEvents>
                                    </sio:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                    </sio:GridPanel>
                </West>
                <Center Split="true">
                    <sio:GridPanel ID="GridNeDodeljeno" Title="Nedodeljene organizacije" runat="server"
                        StripeRows="true" Layout="Fit" Height="300">
                        <Plugins>
                            <ext:GridFilters ID="GridFilters2" runat="server">
                                <Filters>
                                    <ext:NumericFilter DataIndex="OrganizacijaId" />
                                    <ext:StringFilter DataIndex="Naziv" />
                                </Filters>
                            </ext:GridFilters>
                        </Plugins>
                        <Store>
                            <ext:Store ID="StoreGridNeDodeljeno" runat="server">
                                <SortInfo Field="Naziv" />
                                <Reader>
                                    <ext:JsonReader IDProperty="OrganizacijaId">
                                        <Fields>
                                            <ext:RecordField Name="OrganizacijaId" Type="Int" />
                                            <ext:RecordField Name="Naziv" Type="String" />
                                        </Fields>
                                    </ext:JsonReader>
                                </Reader>
                            </ext:Store>
                        </Store>
                        <ColumnModel runat="server">
                            <Columns>
                                <ext:RowNumbererColumn />
                                <ext:Column ColumnID="OrganizacijaId" Hidden="true" Hideable="false" DataIndex="OrganizacijaId">
                                </ext:Column>
                                <ext:Column ColumnID="Naziv" Header="Naziv organizacije" DataIndex="Naziv" Width="150">
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <SelectionModel>
                            <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" />
                        </SelectionModel>
                        <TopBar>
                            <ext:Toolbar runat="server" Width="500">
                                <Items>
                                    <sio:Button runat="server" Text="Dodaj" Icon="ArrowLeft">
                                        <DirectEvents>
                                            <Click OnEvent="DodajOrganizacije" After="#{StoreGridNeDodeljeno}.reload(); #{StoreDodeljeno}.reload();">
                                                <Confirmation ConfirmRequest="true" Message="Dodam izbrane organizacije?" />
                                                <ExtraParams>
                                                    <ext:Parameter Name="selected" Mode="Raw" Value="Ext.encode(#{GridNeDodeljeno}.getRowsValues({selectedOnly:true}))" />
                                                    <ext:Parameter Name="IdmStevilka" Value="#{GridUceciSeznam}.getSelectionModel().hasSelection() ? #{GridUceciSeznam}.getSelectionModel().getSelected().id : -1"
                                                        Mode="Raw" />
                                                </ExtraParams>
                                            </Click>
                                        </DirectEvents>
                                    </sio:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                    </sio:GridPanel>
                </Center>
            </ext:BorderLayout>
        </Content>
    </ext:Viewport>
    <sio:Dialog runat="server" ID="SpremeniGeslo" Width="300" Height="200" Url="../Uporabnik/Spremenigeslo.aspx"
        DialogButtons="SaveClose">
        <Parameters>
            <ext:Parameter Name="Idm" Value="1" Mode="Value" />
        </Parameters>
    </sio:Dialog>
    </form>
</body>
</html>
